import { ReflectMetadataKeys, VerifyPermission } from '@app/common';
import { BatchRemoveDto } from '@app/common/dto/batch-remove.dto';
import { QueryDto } from '@app/modules/query-dto';
import { CreateSencetiveDto } from '@app/modules/sencetive/dto/create-sencetive.dto';
import { UpdateSencetiveDto } from '@app/modules/sencetive/dto/update-sencetive.dto';
import { Sencetive } from '@app/modules/sencetive/entities/sencetive.entity';
import { SencetiveService } from '@app/modules/sencetive/sencetive.service';
import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  ParseArrayPipe,
  ParseIntPipe,
  Patch,
  Post,
  Query,
  SetMetadata,
} from '@nestjs/common';
import {
  ApiBearerAuth,
  ApiBody,
  ApiOperation,
  ApiResponse,
  ApiTags,
} from '@nestjs/swagger';

@ApiTags('敏感词')
@ApiBearerAuth()
@Controller('api/console/sencetive')
@SetMetadata(ReflectMetadataKeys.CONTROLLER_NAME, '敏感词')
export class SencetiveController {
  constructor(private readonly sencetiveService: SencetiveService) {}

  @ApiOperation({ summary: '添加' })
  @ApiBody({ required: true, type: [CreateSencetiveDto] })
  @SetMetadata(ReflectMetadataKeys.ACTION_NAME, '添加')
  @Post()
  @VerifyPermission('site:sencetive:create')
  create(@Body() createSencetiveDto: CreateSencetiveDto[]) {
    return this.sencetiveService.create(createSencetiveDto);
  }

  @ApiOperation({ summary: '列表' })
  @ApiResponse({ status: 200, description: '200', type: [Sencetive] })
  @SetMetadata(ReflectMetadataKeys.ACTION_NAME, '列表')
  @Get()
  @VerifyPermission('site:sencetive:query')
  findAll(@Query() query: QueryDto) {
    return this.sencetiveService.findAll({
      page: query.page || 1,
      limit: query.limit || 10,
    });
  }

  @ApiOperation({ summary: '详细' })
  @ApiResponse({ status: 200, description: '200', type: Sencetive })
  @SetMetadata(ReflectMetadataKeys.ACTION_NAME, '详细')
  @Get(':id')
  @VerifyPermission('site:sencetive:detail')
  findOne(@Param('id', ParseIntPipe) id: number) {
    return this.sencetiveService.findOne(+id);
  }

  @ApiOperation({ summary: '修改' })
  @SetMetadata(ReflectMetadataKeys.ACTION_NAME, '修改')
  @Patch()
  @VerifyPermission('site:sencetive:update')
  update(@Body() updateSencetiveDto: UpdateSencetiveDto[]) {
    return this.sencetiveService.update(updateSencetiveDto);
  }

  @ApiOperation({ summary: '删除' })
  @SetMetadata(ReflectMetadataKeys.ACTION_NAME, '删除')
  @Delete(':id')
  @VerifyPermission('site:sencetive:delete')
  remove(@Param('id', ParseIntPipe) id: number) {
    return this.sencetiveService.remove(+id);
  }

  @ApiOperation({ summary: '批量删除' })
  @SetMetadata(ReflectMetadataKeys.ACTION_NAME, '批量删除')
  @ApiBody({ required: true, description: 'ids', type: BatchRemoveDto })
  @Patch('delete')
  @VerifyPermission('site:sencetive:batDel')
  removeBat(@Body('ids', ParseArrayPipe) ids: number[]) {
    return this.sencetiveService.removeBat(ids);
  }
}
